-
-
Notifications
You must be signed in to change notification settings - Fork 7k
[IDE] Title of sketch is misaligned on Linux FIX #10209 #10210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks for the patch. However:
|
that looks off 2 pixels up. but now it looks off 2 pxels down. IMHO on my system the correct offset should be +1 pixel and not +2. Maybe we should not look the |
I had a test using Descent to calculate "new base line" e looks good.
The questios:
On linux it seems to be more evident, but maybe it's the fact that it's my default OS. The modifications I made tested only on Windows and Linux, and according to the images below it seems to me great. Linux Windows
I believe that it really isn't one of the most interesting pull requests I've ever made ... =] |
I'm not sure if this is really a correct approach though, or whether it just happens to look good. Remember that you're calculating the baseline position, since the baseline will be drawn in the position calculated.
I think this happens to work because the Descent is just 2 pixels. Consider what would happen with a (admittedly weird) font where the descent is 10 pixels. This would end up shifting the baseline 5 pixels down, and the extra descent will extend even below that baseline. Looking more closely at @cmaglie's screenshot, which shows the individual pixels a bit more clearly, I'm a bit surprised. I previously thought that the centering might be correct, but just only the bases of the letters (so excluding e.g. the pole of the b) and the poles just make it look incorrectly centered. But @cmaglie shows that it is actually not doing that, the bit that is centered (e.g. the area that is enclosed between the baseline and a imaginary line above the center at the same distance as the baseline is under the center) is actually smaller than the b-without-pole-area. To make things even more confusing, the image linked by @ricardojlrufino shows that the ascent is actually longer than I had interpreted it (it includes the pole of the b or d). So if So, I actually suspect that something else might be going on:
It might be useful to print the values of |
Place a few lines of reference: And looking for original code:
It seems that the problem is in the fontAscent which has a space left over Output:
|
These pixels more than Coincidentally this problem caused the text to go down, and "look" centered on the tab |
Then we have: 3 pixels of the font, which are not visible .... and 1 pixel lost in the rounding of the header size (35) Dividing by 2, we have the 2 pixels that I had initially used to correct ... |
Nice, good to have a detailed idea of what is going on. So, there's two problems:
Since both introduce opposite errors, most of the error is cancelled out. Fixing 1. is obvious, just adjust the calculation to use the actual tab size. This is probably easiest by introducing a constant into the code that hardcodes the tab size (since I think the tab images are full-height with some transparent pixels at the top, so you cannot easily derive it from those). Fixing 2. is more tricky, since we rely on java and/or the font to return meaningful values. It really looks like the returned value is wrong, though, I wonder if there are any characters at all that extend up to the full ascent value? We can hardcode an offset for this particular font, but different systems and different fonts might then get messed up again. One approach could be to check if the ascent and max ascent are equal, and if so, apply a correction on the ascent (still not ideal, but at least other fonts that do make a distinction will not get over-corrected then). |
java.awt.FontMetrics getAscent() returns getMaxAscent()
If these characters exist today, the misalignment for them will become more evident in the current implementation. |
What do you think about having the 'hardcoded' ajust for the default font "SansSerif" and highlight it as a fix for this Java bug. That could be removed when the bug is resolved (I doubt it ... lol) ? This is a problem that has existed for a long time ... based on the screenshots of the IDE's prints that I've been looking for on the internet. |
Hm, I had considered suggesting this (fixing 1. and leaving 2. broken), but decided that would not look good so I didn't. Turns out it does actually look ok indeed. Apparently slightly too low is ok, while slightly too high is not :-) The code looks good to me, if you push that to this PR, I'd approve it :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
Would still need to be squashed into a single commit before merging, though.
Tested on Windows looks fine too. Thanks! |
All Submissions:
Details
For a long time I always found the linux icon out of alignment, I attribute this problem that was perhaps related to my system fonts. But I think that need a HACK for Linux / Ubuntu
Tests:
Os: Kubuntu / KDE
JDK: OpenJDK 7 and 11
But I decided to investigate further, and looking at some prints on the internet I see that it is really out of alignment.
http://dexvils.blogspot.com/2015/06/install-arduino-ide-16x-on-ubuntu.html
https://websiteforstudents.com/how-to-install-arduino-ide-on-ubuntu-18-04-16-04/